package com.nulldev.util.java.swing.extSwing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.nulldev.util.java.JVMUtil;
import com.nulldev.util.java.swing.SwingUtil;
import com.nulldev.util.java.swing.canvas.PaintMethod;
import com.nulldev.util.java.swing.canvas.SmoothCanvas;
import com.nulldev.util.java.swing.extSwing.lookandfeel.themes.ThemeApplier;
import com.nulldev.util.java.swing.font.FontManager;
import com.nulldev.util.java.utils.color.ColorUtil;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JSeparator;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.border.LineBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.BevelBorder;
import javax.swing.border.EtchedBorder;

public class eLoginPane2 extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField pwdFgfg;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		JVMUtil.setArgs(args);
		if (JVMUtil.isArg("--fonts")) {
			FontManager.loadSystemSpecificFonts();
		}
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					eLoginPane2 frame = new eLoginPane2();
					ThemeApplier.applyTheme(frame);
					SwingUtil.centerFrame(frame);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public eLoginPane2() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(eLoginPane2.class.getResource("/com/nulldev/util/java/swing/nullutil_logo.png")));
		setTitle("Login");
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 526, 314);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		
		JSeparator separator = new JSeparator() {
			@Override
			public void setForeground(final Color color) {
				super.setForeground(ColorUtil.rainbow(20, 1f));
			}
		};
		
		JLabel lblEloginpanelogo = new JLabel("eLoginPane2.logo");
		
		JLabel lblUsername = new JLabel("Username");
		
		textField = new JTextField();
		textField.setBorder(new PolyBorder(Color.YELLOW));
		textField.setColumns(10);
		
		JLabel lblPassword = new JLabel("Password");
		
		pwdFgfg = new JPasswordField();
		pwdFgfg.setBorder(new PolyBorder(Color.YELLOW));
		pwdFgfg.setEchoChar('*');
		
		JButton btnLogin = new JButton("Login");
		
		final SmoothCanvas panel_1 = new SmoothCanvas() {
			
			@Override
			public void drawCanvas(Graphics2D g2d) {
				g2d.setColor(contentPane.getBackground());
				g2d.fillRect(0, 0, getWidth(), getHeight());
				g2d.setColor(ColorUtil.rainbow(20, 1.0f));
				g2d.fillOval(5, 5, 20, 20);
			}
		};
		panel_1.setAAEnabled(true);
		panel_1.usePaintMethod(PaintMethod.REPAINT);
		
		JLabel lblLoggingIn = new JLabel("Logging in...");
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addComponent(panel, GroupLayout.DEFAULT_SIZE, 514, Short.MAX_VALUE)
				.addComponent(separator, GroupLayout.PREFERRED_SIZE, 514, Short.MAX_VALUE)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblEloginpanelogo)
					.addContainerGap(374, Short.MAX_VALUE))
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblUsername)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textField, GroupLayout.DEFAULT_SIZE, 406, Short.MAX_VALUE)
					.addContainerGap())
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblPassword)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(pwdFgfg, GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
					.addContainerGap())
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 27, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(lblLoggingIn)
					.addPreferredGap(ComponentPlacement.RELATED, 308, Short.MAX_VALUE)
					.addComponent(btnLogin)
					.addContainerGap())
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(lblEloginpanelogo)
					.addGap(33)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblUsername)
						.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblPassword)
						.addComponent(pwdFgfg, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 99, Short.MAX_VALUE)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING, false)
						.addComponent(panel_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
						.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
							.addComponent(btnLogin, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(lblLoggingIn)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(separator, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE))
		);
		panel.setLayout(new BorderLayout(0, 0));
		
		JButton btnLoginUsingSmartlogin = new JButton("Login using SmartLogin");
		btnLoginUsingSmartlogin.setVisible(false);
		panel.add(btnLoginUsingSmartlogin, BorderLayout.CENTER);
		contentPane.setLayout(gl_contentPane);
	}
}
